#include <iostream>
using namespace std;

int myadd(int num1, int num2)
{
    return num1 + num2;
}

float myadd(float num1, float num2)
{
    return num1 + num2;
}

class Point
{
public:
    Point() : Point(0, 0)
    {
    }
    Point(int x, int y) : m_x(x), m_y(y)
    {
    }

public:
    Point operator+(const Point &point);
    friend ostream &operator<<(ostream &cout, const Point &p);

public:
    int m_x;
    int m_y;
};

Point myadd(Point p1, Point p2)
{
    return p1 + p2;
}

Point Point::operator+(const Point &point)
{
    Point res(0, 0);
    res.m_x = this->m_x + point.m_x;
    res.m_y = this->m_y + point.m_y;
    return res;
}

ostream &operator<<(ostream &cout, const Point &p)
{
    cout << "(" << p.m_x << ", " << p.m_y << ")";
    return cout;
}

template <class T>
class SmartPointer
{
public:
    /*构造函数*/
    SmartPointer(T *pointer)
    {
        cout << "SmartPointer()" << endl;
        m_pointer = pointer;
    }
    /*析构函数*/
    ~SmartPointer()
    {
        cout << "~SmartPointer()" << endl;
        if (m_pointer != NULL)
        {
            /*只有是数组的时候，在释放空间才使用的是delete[].*/
            delete[] m_pointer;
            m_pointer == NULL
        }
    }

private:
    /*指针*/
    T *m_pointer;
};

// SmartPointer::SmartPointer(/* args */)
// {
// }

// SmartPointer::~SmartPointer()
// {
// }

int main()
{
#if 0
    /*随机值 指针必须赋初值.*/
    int *ptr = NULL;
    ptr = new int[10]; // 5
    for (int idx = 0; idx < 10; idx++)
    {
        printf("ptr[%d]= %d\n", idx, ptr[idx]);
    }
    /*使用new分配的堆空间 没有脏数据.*/


    printf("*ptr = %d\n", *ptr);

if(ptr != NULL)
{
    delete [] ptr;
    /* delete 并不会将指针置为NULL,需要手动置为NULL.*/
}

    printf("*ptr = %d\n", *ptr);
#endif

    SmartPointer<int> ptr(new int[5]);

    /* shared ptr循环引用 */
    shared ptr<Person> person(new Person);
    shared_ptr<Car> car(new Car);

    return 0;
}
